package book;

// 税率计算基类
public class ComputeTax {
    /**
     * 计算税款
     *
     * @param income 收入
     * @param type   纳税人类型 1-单身纳税人 2-已婚纳税人 3-家庭纳税人
     * @return 应交税款
     */
    public void TaxRate(double income, int type) {
        double rate;
        switch (type) {
            case 1: // 单身纳税人
                rate = SingleRate(income);
                break;
            case 2: // 已婚纳税人
                rate = MarraryRate(income);
                break;
            case 3: // 家庭纳税人
                rate = FamilyRate(income);
                break;
            default:
                rate = 0;

        }
        double tax = income * rate;
        System.out.println("税率为：" + rate);
        System.out.println("应缴纳税款：" + tax);
    }


    /**
     * 税率计算
     *
     * @param income 收入
     * @return 返回税率
     */
    private double CountRate(double income, double[] incomeDevidePointList, double[] rateList) {
        if (income < incomeDevidePointList[0]) {
            return rateList[0];
        } else if (income < incomeDevidePointList[1]) {
            return rateList[1];
        } else if (income < incomeDevidePointList[2]) {
            return rateList[2];
        } else if (income < incomeDevidePointList[3]) {
            return rateList[3];
        } else {
            return rateList[4];
        }
    }

    /**
     * 单身纳税人税率计算
     *
     * @param income 收入
     * @return 返回税率
     */
    private double SingleRate(double income) {
        double[] incomeDevidePointList = {6000, 27950, 67700, 141250}; // 收入划分
        double[] rateList = {0.1, 0.15, 0.27, 0.3, 0.35};// 税率
        return CountRate(income, incomeDevidePointList, rateList);
    }

    /**
     * 已婚纳税人
     *
     * @param income 收入
     * @return 返回税率
     */
    private double MarraryRate(double income) {
        double[] incomeDevidePointList = {12000, 46700, 112850, 171950}; // 收入划分
        double[] rateList = {0.1, 0.15, 0.27, 0.3, 0.35};// 税率
        return CountRate(income, incomeDevidePointList, rateList);
    }

    /**
     * 家庭纳税人
     *
     * @param income 收入
     * @return 返回税率
     */
    private double FamilyRate(double income) {
        double[] incomeDevidePointList = {10000, 37450, 96700, 156600}; // 收入划分
        double[] rateList = {0.1, 0.15, 0.27, 0.3, 0.35};// 税率
        return CountRate(income, incomeDevidePointList, rateList);
    }
}
